import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:meePet/app/LocalColor.dart';
import 'package:meePet/manager/RouteManager.dart';
import 'package:meePet/utils/LogUtils.dart';
import 'package:webview_flutter/webview_flutter.dart';

import '../widgets/view/ComomAppBarView.dart';
import 'WebVM.dart';

class WebPage extends StatelessWidget {
  final WebVM viewModel = Get.put(WebVM());

  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: const SystemUiOverlayStyle(
/*statusBarColor: Colors.transparent,//状态栏颜色
          statusBarIconBrightness: Brightness.dark, //状态栏图标颜色
          statusBarBrightness: Brightness.dark,  //状态栏亮度
          systemStatusBarContrastEnforced: true, //系统状态栏对比度强制*/

        systemNavigationBarColor: Color.fromRGBO(19, 18, 24, 1),
//导航栏颜色
        systemNavigationBarIconBrightness: Brightness.dark,
//导航栏图标颜色
        systemNavigationBarDividerColor: Color.fromRGBO(19, 18, 24, 1),
//系统导航栏分隔线颜色
        systemNavigationBarContrastEnforced: false, //系统导航栏对比度强制
      ),
      child: getScaffold(context),
    );
  }

  Widget getScaffold(BuildContext context) {
    return Scaffold(
      appBar: null,
      body: _rootLayout(context),
    );
  }

  ///根布局
  Widget _rootLayout(BuildContext context) {
    return Stack(
      children: [
        SizedBox(
          width: double.infinity,
          height: double.infinity,
          child: DecoratedBox(
              decoration: BoxDecoration(color: LocalColor.colorWhite)),
        ),
        Column(
          children: [
            Offstage(
              offstage: false,
              child: CommonAppBar("", () {
                LogUtils.i("点击了退出网页");
                RouteManager.back();
              }),
            ),
            Expanded(
                child: Obx(()=>WebView(
                  initialUrl: viewModel.url.value,
                  javascriptMode: JavascriptMode.unrestricted,
                  onPageFinished: (String s) {
                    viewModel.loading.value = false;
                  },
                ))),
          ],
        ),
        Obx(() => Offstage(
              offstage: !viewModel.loading.value,
              child: Container(
                width: MediaQuery.of(context).size.width,
                height: MediaQuery.of(context).size.height,
                color: LocalColor.colorWhite,
              ),
            )),
      ],
    );
  }
}
